#include<iostream>

using namespace std;
const int N=1e5+10;
int nums[N];
int leftflag(int n,int tar)
{
	//查找>tar的最小坐标，=tar的最大坐标
	int left=1,right=n;
	int flag=-1;
	while(left<=right)
	{
		int mid=left+(right-left)/2;
		if(nums[mid]>=tar)
		{
			flag=mid;
			right=mid-1;
		}
		else
		{
			left=mid+1;
		}
	}
	return flag;
}
int rightflag(int n,int tar)
{
	//查找<tar2的最大坐标,=tar2的最小坐标
	int flag=-1;
	int left=1,right=n;
	while(left<=right)
	{
		int mid=left+(right-left+1)/2;
		if(nums[mid]<=tar)
		{
			flag=mid;
			left=mid+1;
		}
		else
		{
			right=mid-1;
		}
	}
	return flag;
}
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>nums[i];
	}

	int q;cin>>q;
	while(q--)
	{
		int x,y;cin>>x>>y;
		int left=leftflag(n,x);
		int right=rightflag(n,y);
		if(left==-1||right==-1)
		{
			cout<<0<<endl;
		}
		else
		{
			cout<<abs(right-left+1)<<endl;
		}
	}
}